package com.ibm.spatiotemp.server.framework.processor;

import org.apache.log4j.Logger;

import com.ibm.spatiotemp.server.datasources.DataSource;
import com.ibm.spatiotemp.server.framework.request.Request;

public abstract class SpatialQueryProcessor {
	public static Logger logger = Logger.getLogger(SpatialQueryProcessor.class);
	
	protected DataSource datasource;
	
	public SpatialQueryProcessor(DataSource src)
	{
		this.datasource = src;
	}
	
	/*notice here return string is in json format*/
	
	/*
	 * Method: GET /tenant1?queryType=position&time=2014-01-01T00:00:20&&bbox=[-122.40327,37.52015,-122.3101,37.90572]
		Returns:
           [{
            "id": “uuid1",
            "key": "myMovingObject",
            “position": [25,36], "time": ["2014-01-01T00:00:20“]
           },
           {"id": "uuid2","key": "anotherMovingObject","position": [400,2],
           "time": [ 1�714-01-01T00:00:20”]}
           ]
*/
	public static String PositionQueryElementFormat = 
			"{\"id\":\"%s\","
			+ "\"key\":\"%s\","
			+ "\"position\":[%f,%f],"
			+ "\"time\":[\"%s\"]"
			+ "}";
	public static String PositionQueryResponseFormat = "[%s]";
	public abstract String handlePositionQuery(Request request) throws Exception;
	
	
	/*trajectory query type 1*/
	/*
	 * Method: GET /tenant1?queryType=trajectory&id=uuid1&start=2014-01-01T00:00:00&end=2014-02-01T00:00:00
Returns:
           [{
            "id": “uuid1",
            "key": "myMovingObject",
            "trajectory": {
              "type": "LineString",
              "coordinates": [[-50,53], [25,36], [75,50], [150, 32]]
            },
           "time": ["2014-01-01T00:00:00", "2014-01-01T00:00:20",
                       "2014-01-01T00:00:30", "2014-01-01T00:00:55"]
           }]
	 * 
	 * */
	public static String TrajectoryResponseType1Format =
		"[{\"id\":\"%s\","
		+ "\"key\":\"%s\","
		+ "\"trajectory\":%s,"
		+ "\"time\":[%s]"
		+ "}]";
	public static String LineStringFormat =
			"{\"type\":LineString,"
			+ "\"coordinates\":%s}";
	
	
	/*trajectory query type 2*/
	/*
	 * Method: GET /tenant1?queryType=trajectory&start=2014-01-01T00:00:00&end=2014-02-01T00:00:00&bbox=[-122.40327,37.52015,-122.3101,37.90572]&bboxRel=intersect
Returns:  [
            {
            "id": “uuid1",
            "key": "myMovingObject",
            "trajectory": {
              "type": "LineString",
              "coordinates": [[-50,53], [25,36], [75,50], [150, 32]]
            },
           "time": ["2014-01-01T00:00:00", "2014-01-01T00:00:20", 1�7
                       "2014-01-01T00:00:30", "2014-01-01T00:00:55"] 1�7
           },
           {
            "id": “uuid2",
           …�1�7�1�7.
          },…�1�7�1�7
       ]
	 * 
	 * */
	public static String TrajectoryResponseType2ElementFormat =
			"{\"id\":\"%s\","
			+ "\"key\":\"%s\","
			+ "\"trajectory\":%s,"
			+ "\"time\":[%s]"
			+ "}";
	public static String TrajectoryResponseType2ResponseFormat =
			"[%s]";
	public abstract String handleTrajectoryQuery(Request request) throws Exception;
	
	/*
	 * 
	 * Method: GET /tenant1?queryType=firsttime&id=uuid1&position=[25,36]&distance=5&start=2014-01-01T00:00:00&end=2014-02-01T00:00:00
		Returns: 
           [{
            "id": “uuid1",
            "key": "myMovingObject",
            “position": [25,36], "time": ["2014-01-01T00:00:20“]
           }]
	 * */
	public static String TimeQueryResponseFormat = 
			"[{\"id\":\"%s\","
			+ "\"key\":\"%s\","
			+ "\"position\":[%f,%f],"
			+ "\"time\":[\"%s\"]"
			+ "}]";
	public abstract String handleTimeQuery(Request request) throws Exception;
}
